package untiring.controllers;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import untiring.interfaces.MemberService;
import untiring.interfaces.ProductService;
import untiring.models.GalleryVO;
import untiring.models.ProductVO;

@Controller
public class ProductController {
	
	@Autowired
	private MemberService memberService;
	@Autowired
	private ProductService productService;
	
	@RequestMapping(value="/man/tlist", method = RequestMethod.GET)
	public String tman(Model model) throws Exception{
		model.addAttribute("product", productService.readProduct());
		return "man/tlist";
	}
	
	
	@RequestMapping(value="/man/blist", method = RequestMethod.GET)
	public String bman() throws Exception{
		return "man/blist";
	}
	@RequestMapping(value="/man/olist", method = RequestMethod.GET)
	public String oman() throws Exception{
		return "man/olist";
	}
	@RequestMapping(value="/man/view", method = RequestMethod.GET)
	public String manview(Model model, @RequestParam String pno) throws Exception{
		System.out.println(pno);
		model.addAttribute("products", productService.readOneProduct(pno));
		
		return "man/view";
	}
	
	@RequestMapping(value="/woman/tlist", method = RequestMethod.GET)
	public String twoman() throws Exception{
		return "woman/tlist";
	}
	@RequestMapping(value="/woman/olist", method = RequestMethod.GET)
	public String owoman() throws Exception{
		return "woman/olist";
	}
	@RequestMapping(value="/woman/blist", method = RequestMethod.GET)
	public String bwoman() throws Exception{
		return "woman/blist";
	}
	
	@RequestMapping(value="/accessory/bag", method = RequestMethod.GET)
	public String bag() throws Exception{
		return "accessory/bag";
	}
	@RequestMapping(value="/accessory/cap", method = RequestMethod.GET)
	public String cap() throws Exception{
		return "accessory/cap";
	}
	@RequestMapping(value="/accessory/etc", method = RequestMethod.GET)
	public String etc() throws Exception{
		return "accessory/etc";
	}
	@RequestMapping(value="/accessory/view", method = RequestMethod.GET)
	public String aview() throws Exception{
		return "accessory/view";
	}
	
	@RequestMapping(value="/sale/slist", method = RequestMethod.GET)
	public String slist() throws Exception{
		return "sale/slist";
	}
	
	@RequestMapping(value="/sale/view", method = RequestMethod.GET)
	public String sview() throws Exception{
		return "sale/view";
	}
	
	@RequestMapping("/image")
	   @ResponseBody
	   public byte[] image(@ModelAttribute ProductVO p, HttpServletResponse res) throws Exception {      
	      return productService.viewImage(p, res);
	   }
	
}
